<?php

	class Devmod_method_castField_rawimage extends Devmod_castField_abstraction {
		
		public function type_add()
		{
			// image id: $value
			
			$img = null;
			
			$this->view->assign(array(
				'field_name' => $this->cfg['field_name'],
				'value' => '',
				'img' => $img,
				'theme' => $this->view->theme,
				'type' => 'add'
			));
			
			$this->view->append('tpl_addons', $this->view->fetch('common/cast_rawimage.tpl'));
			
			return $this->view->fetch('common/cast_rawimage_show.tpl');
		}
		
		public function type_edit()
		{
			// image id: $value
			
			$img = null;
			
			if($this->value !== "0" && isset($this->value) && !empty($this->value))
			{
				$extension = $this->db->select("file_lib", "name", "WHERE id='{$this->value}'", false)->name;
				$img = SiteConfig::Domain . Yomm_Config::DIR_FILES_PATH . $this->value . '.' . $extension;
			}
			
			$this->view->assign(array(
				'field_name' => $this->cfg['field_name'],
				'value' => $this->value,
				'img' => $img,
				'theme' => $this->view->theme,
				'type' => 'edit'
			));
			
			$this->view->append('tpl_addons', $this->view->fetch('common/cast_rawimage.tpl'));
			
			return $this->view->fetch('common/cast_rawimage_show.tpl');
		}
		
		public function type_frontend_list()
		{
			if(empty($this->value)) return 'no_file';
			
			$extension = $this->db->select("file_lib", "name", "WHERE id='{$this->value}'", false)->name;
			
			$img = SiteConfig::Domain . Yomm_Config::DIR_FILES_PATH . $this->value . '.' . $extension;
			
			return $img;
		}
		
		public function type_list()
		{
			if(!isset($this->value)) return "no_rawimage";
			
			$extension = $this->db->select("file_lib", "name", "WHERE id='{$this->value}'", false)->name;
			
			$img = SiteConfig::Domain . Yomm_Config::DIR_FILES_PATH . $this->value . '.' . $extension;
			
			return $img;
		}
		
	}